﻿//===============================================================================
// Microsoft Platform Architecture Team
// LitwareHR - S+S Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GeoRss;

namespace GeoRSSTest
{
    /// <summary>
    /// Summary description for TestGeoRSS
    /// </summary>
    [TestClass]
    public class GeoRssDataBasicAndPointFixture
    {
        public GeoRssDataBasicAndPointFixture()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void CreatesEmptyRSSFeed()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");

            Assert.AreEqual(grssb.Description, "description");
            Assert.AreEqual(grssb.Title, "title");
            Assert.AreEqual(0, grssb.Items.Count);
        }

        [TestMethod]
        public void CreatesRSSFeedWithOneItem()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            grssb.Items.Add(new GeoRssItem() { Title = "item_title", Description = "item_description", Icon = "it_icon", Link = "it_link" });
            Assert.AreEqual(grssb.Description, "description");
            Assert.AreEqual(grssb.Title, "title");
            Assert.AreEqual(1, grssb.Items.Count);
            Assert.AreEqual("item_title", grssb.Items[0].Title);
        }

        [TestMethod]
        public void AddsItemWithLongitudeAndLatitude()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            GeoRss.GeoRssPointItem item = grssb.AddPoint("item_title", "item_content", 2.2, 1.1);

            Assert.AreEqual("item_title", item.Title);
            Assert.AreEqual("item_content", item.Description);
            Assert.AreEqual(1, grssb.Items.Count);
            Assert.AreEqual(2.2, (grssb.Items[0] as GeoRssPointItem).Point.Latitude);
            Assert.AreEqual(1.1, (grssb.Items[0] as GeoRssPointItem).Point.Longitude);
            Assert.IsTrue(String.IsNullOrEmpty(item.Icon));
            Assert.IsTrue(String.IsNullOrEmpty(item.Link));
        }

        [TestMethod]
        public void AddsItemWithLongitudeAndLatitudeAndIcon()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            GeoRss.GeoRssPointItem item = grssb.AddPoint("item_title", "item_content", 2.2, 1.1);
            item.Icon = "icon";

            Assert.AreEqual("item_title", item.Title);
            Assert.AreEqual("item_content", item.Description);
            Assert.AreEqual(1, grssb.Items.Count);
            Assert.AreEqual(2.2, (grssb.Items[0] as GeoRssPointItem).Point.Latitude);
            Assert.AreEqual(1.1, (grssb.Items[0] as GeoRssPointItem).Point.Longitude);
            Assert.AreEqual("icon", item.Icon);
            Assert.IsTrue(String.IsNullOrEmpty(item.Link));
        }

        [TestMethod]
        public void Adds3ItemsWithLongitudeAndLatitude()
        {
            GeoRss.GeoRssData grssb = new GeoRss.GeoRssData("title", "description");
            GeoRss.GeoRssItem item1 = grssb.AddPoint("title", "content", 1.1, 2.2);
            GeoRss.GeoRssItem item2 = grssb.AddPoint("title2", "content2", 2.2, 3.3);
            GeoRss.GeoRssItem item3 = grssb.AddPoint("title3", "content3", 3.3, 4.4);

            Assert.AreEqual(3, grssb.Items.Count);

            Assert.AreEqual("title3", grssb.Items.Where( i => i.Title == "title3" ).SingleOrDefault().Title);
            Assert.AreEqual("title2", grssb.Items.Where(i => i.Title == "title2").SingleOrDefault().Title);
            Assert.AreEqual("title", grssb.Items.Where(i => i.Title == "title").SingleOrDefault().Title);
        }
    }
}